import { Injectable } from '@nestjs/common';
import * as AWS from 'aws-sdk';

AWS.config.update({
  region: 'us-east-1',
  accessKeyId: 'AKIAJAOIL3QW7GH5AUUA',
  secretAccessKey: '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',
});

const SNS = new AWS.SNS({ apiVersion: '2010-03-31' });

@Injectable()
export class SMSChannelService {
  async sendSMS(to: string, content: string): Promise<boolean> {
    return new Promise<boolean>((resolve, reject) => {
      SNS.publish(
        {
          Message: content,
          PhoneNumber: to,
        },
        (err, data) => {
          if (err) {
            console.log(err.message);
            reject(err);
          } else {
            console.log('SMS sent! Message ID: ', data.MessageId);
            resolve(true);
          }
        },
      );
    });
  }
}
